package com.smart_campus.teg.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.smart_campus.sys.common.DataGridView;
import com.smart_campus.sys.domain.User;
import com.smart_campus.teg.vo.DutyVo;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import com.smart_campus.teg.mapper.TegDutyMapper;
import com.smart_campus.teg.domain.TegDuty;
import com.smart_campus.teg.service.TegDutyService;

import java.util.List;

/**
 * @author Alfred
 * @time: 2020/6/30 20:09
 * 
 */
@Service
public class TegDutyServiceImpl implements TegDutyService{

    @Resource
    private TegDutyMapper tegDutyMapper;

    //@CacheEvict 删除的注解通过对象id在redis中删除数据
    @CacheEvict(cacheNames = "com.smart_campus.teg.service.impl.TegDutyServiceImpl",key = "#id")
    @Override
    public int deleteByPrimaryKey(Integer id) {
        return tegDutyMapper.deleteByPrimaryKey(id);
    }

    //@CachePut 要返回对象 添加通过reids主键回填的id来在redis创建对应id的对象数据
    @CachePut(cacheNames = "com.smart_campus.teg.service.impl.TegDutyServiceImpl",key = "#result.id")
    @Override
    public TegDuty insert(TegDuty record) {
        tegDutyMapper.insert(record);
        return record;
    }

    //@CachePut 要返回对象 添加通过reids主键回填的id来在redis创建对应id的对象数据
    @CachePut(cacheNames = "com.smart_campus.teg.service.impl.TegDutyServiceImpl",key = "#result.id")
    @Override
    public TegDuty insertSelective(TegDuty record) {
        tegDutyMapper.insertSelective(record);
        return record;
    }

    //@Cacheable 返回对象 通过对象id在redis中创建对象保存,方便下次使用
    @Cacheable(cacheNames ="com.smart_campus.teg.service.impl.TegDutyServiceImpl",key = "#id")
    @Override
    public TegDuty selectByPrimaryKey(Integer id) {
        return tegDutyMapper.selectByPrimaryKey(id);
    }

    //@CachePut 要返回对象 添加通过reids主键回填的id来在redis创建对应id的对象数据
    @CachePut(cacheNames = "com.smart_campus.teg.service.impl.TegDutyServiceImpl",key = "#result.id")
    @Override
    public TegDuty updateByPrimaryKeySelective(TegDuty record) {
        tegDutyMapper.updateByPrimaryKeySelective(record);
        return record;
    }

    //@CachePut 要返回对象 添加通过reids主键回填的id来在redis创建对应id的对象数据
    @CachePut(cacheNames = "com.smart_campus.teg.service.impl.TegDutyServiceImpl",key = "#result.id")
    @Override
    public TegDuty updateByPrimaryKey(TegDuty record) {
        tegDutyMapper.updateByPrimaryKey(record);
        return record;
    }

    @Override
    public DataGridView selAllDuty(DutyVo dutyVo) {
        Page<Object>page= PageHelper.startPage(dutyVo.getPage(),dutyVo.getLimit());
        List<DutyVo>dutyVoList = this.tegDutyMapper.selAllDuty(dutyVo);
        return new DataGridView(page.getTotal(),dutyVoList);
    }

    @Override
    public DataGridView getAllStaff() {
        List<User> dutyList = this.tegDutyMapper.getAllStaff();
        return new DataGridView(dutyList);
    }
}
